package com.tzl.leetcode.editor.cn;

//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean isPalindrome(int x) {
        // 负数，个位=0的数都不可能是回文数
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        // 反转一半，如果反转后==反转前，则是回文数
        int rev = 0;
        // 当下《= rev时，则表示反转了一半了
        while (x > rev) {
            int digit = x % 10;
            x /= 10;
            rev = rev * 10 + digit;
        }
        return x == rev || x == rev / 10;
    }
}
//leetcode submit region end(Prohibit modification and deletion)
